<?php
namespace app\home\controller;
use app\home\model\TopicnewsModel;
use \think\Controller;
use \think\Session;

class Topicnews extends Controller
{
    /**
     * 话题详情
     */
    public function getTopicDetails(){
        $id = input('id');
        $community_id = input('community_id');
        $getRowTopicDetails = new TopicnewsModel();
        $getRowTopicDetails = $getRowTopicDetails->topicDetails($id);
        $gatRowsTopicNewsDetails = new TopicnewsModel();
        $gatRowsTopicNewsDetails = $gatRowsTopicNewsDetails->topicCommentDetails($id);
        foreach($gatRowsTopicNewsDetails as $key => $val){
            $user_name = new TopicnewsModel();
            $user_name = $user_name->user_name($val['user_id']);
            $gatRowsTopicNewsDetails[$key]['user_name'] = $user_name['user_name'];
        }
        $this->assign('topicDetails', $getRowTopicDetails);
        $this->assign('community_id', $community_id);
        $this->assign('RowsTopicNewsDetails', $gatRowsTopicNewsDetails);
        return $this->fetch('topic_details');
    }

    /**
     * 发表评论
     */
    public function addComment(){
        if(Session::get('USER.id') == ''){
            return 'login';
        }
        $topic_id = input('topic_id');
        $content = input('content');
        if($content == ''){
            return 'empty_content';
        }
        $data = [
            'user_id' => Session::get('USER.id'),
            'topic_id' => $topic_id,
            'topic_news_content' => $content,
            'reply_time' => time()
        ];
        $addComment = new TopicnewsModel();
        $addComment = $addComment->addComment($data);
        return $addComment;
    }


}